package com.demohomework.homeworkdemo.mapper;

import com.demohomework.homeworkdemo.pojo.Admin;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdminMapper {

    //根据用户名查询用户信息
    @Select("select * from admin where username = #{username}")
    Admin findbyUsername(String username);

    //添加用户信息
    @Insert("insert into admin(username, password,created_at, updated_at) values(#{username}, #{md5Password},  now(), now())")
    void add(String username, String md5Password);

    //更新用户信息
    @Update("update admin set name = #{name}, phone = #{phone}, email = #{email}, updated_at = now() where id = #{id}")
    void update(Admin admin);

    //更新用户密码
    @Update("update admin set password = #{md5Password}, updated_at = now() where id = #{id}")
    void updatePwd(String md5Password, Integer id);

    //查询所有用户信息
    @Select("select * from admin")
    List<Admin> list();

    //删除用户信息
    @Delete("delete from admin where id = #{id}")
    void delete(Integer id);

    //管理员添加用户信息
    @Insert("insert into admin(username, password, name, phone, email, created_at, updated_at) values(#{username}, #{password}, #{name}, #{phone}, #{email}, now(), now())")
    void adminAdd(Admin admin);
}
